//
//  File.swift
//
//
//  Created by didi on 2022/9/9.
//

import Fluent
import Vapor

public struct SystemApi {
    private var db: Database

    public var permission: SystemPermissionApi { .init(.init(db)) }
    public var variable: SystemVariableApi { .init(.init(db)) }
    public var metadata: SystemMetadataApi { .init(.init(db)) }

    init(_ db: Database) {
        self.db = db
    }
}

public extension Request {
    var system: SystemApi { .init(db) }
}

extension Application {
    var system: SystemApi { .init(db) }
}

public extension TemplateEngine {
    var system: SystemModuleTemplate {
        self.get(SystemModuleTemplate.self)
    }
}
